<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<script type="text/javascript">

    var area;
    function addTextArea() {
        area = new nicEditor({fullPanel : false, buttonList : ['bold','italic','underline','left','center','right','justify','ol','ul','fontSize','fontFamily','fontFormat','indent','outdent','link','unlink','forecolor','bgcolor']}).panelInstance('description');
    }
    bkLib.onDomLoaded(function() { addTextArea();});
</script>
<div id="product">
    <div id="form">
        <form:form method="post" commandName="product" enctype="multipart/form-data">
            <c:choose>
                <c:when test="${edit!=null && edit==true}">
                    <b>Edytuj produkt</b><br>
                    Ostatnia modyfikacja: ${product.addDate}
                    <form:hidden path="idproduct"/>
                    <form:hidden path="picturelink"/>
                </c:when>
                <c:otherwise>
                    <b>Dodaj nowy produkt</b><br>
                </c:otherwise>
            </c:choose>
            <table>
                <tr><td class="label">Nazwa produktu:</td><td><form:input path="productname"/> <span class="error"><form:errors path="productname" /></span></td></tr>
                <tr><td class="label">Kategoria:</td><td>
                <form:select path="category.idcategory">
                    <form:option value="0" label="Wybierz kategorie..."/>
                        <c:forEach items="${categoryList}" var="cat">
                            <form:option value="${cat.idcategory}" label="${cat.categoryname}"/>
                        </c:forEach>
                 </form:select>
                <span class="error"><form:errors path="category.idcategory" /></span></td></tr>
                <tr><td class="label">Cena:</td><td class="price"><form:input path="price"/> <span class="error"><form:errors path="price" /></span></td></tr>
                <tr><td class="label">Ilość:</td><td class="price"><form:input path="amount"/> <span class="error"><form:errors path="amount" /></span></td></tr>
                <tr><td class="label">Zdjęcie:</td><td><form:input path="fileData" type="file"/><br><c:if test="${product.picturelink!=null && product.picturelink!=\"\"}"><img src="../../apteka_photos/${product.picturelink}"></c:if></td></tr>
                <tr><td class="label">Krótki opis:</td><td class="short_desc"><form:textarea path="short_desc"/></td></tr>
                <tr><td class="label">Opis:</td><td class="desc"><form:textarea path="description"/></td></tr>
                <tr><td></td><td>
                        <c:choose>
                            <c:when test="${edit!=null && edit==true}">
                                <input type="submit" value="Zapisz">
                            </c:when>
                            <c:otherwise>
                                <input type="submit" value="Dodaj">
                            </c:otherwise>
                        </c:choose>
                </td></tr>
            </table>

        </form:form>
    </div>
</div>